home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10702 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q about the float point format......
  5. Date: 19 Mar 1996 07:40 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <19MAR199607404893@erich.triumf.ca>
  9. References: <s3032089.15.314E68DD@sparc13.ncu.edu.tw>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <s3032089.15.314E68DD@sparc13.ncu.edu.tw>, s3032089@sparc13.ncu.edu.tw (Alexander PeaceLand) writes...
  14. >   Could I dynamicly set the digits after the float POINT?
  15. >   In other word... I use printf to print the float point number
  16. >                    like 123.456789 but in the other time i only 
  17. >                    want to print 123.456 or 123.4 
  18. >                    How shall I do? Thanks! :)
  19.  
  20. Read the printf() man pages about width and precision  specifiers.
  21. Try something like:
  22.     float f = 123.45678;
  23.     printf("%6.2f", f);
  24. Should print 123.46
  25.  
  26. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  27. Internet: bennett@triumf.ca         | of one another only when one can be
  28. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  29. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  30. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  31. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  32.  
  33.